<?php
require "./function.php";
/**
 * @Author: Wherein
 * @Date: 2021-03-15 12:30
 * @covers 抽象工厂模式
 * @Descripttion: 
 */

/**
 * 手机产品接口
 * @author Wherein <wherein777@163.com>
 * @date 2021-03-15 14:57
 */
interface IphoneProduct
{
    // 功能
    public function start();
    public function shutdown();
    public function callup();
    public function sendSMS();
}
/**
 * 路由器产品接口
 * @author Wherein <wherein777@163.com>
 * @date 2021-03-15 14:58
 */
interface IRouteProduct
{
    public function start();
    public function shutdown();
    public function openWifi();
    public function setting();
}


/**
 * 小米手机
 * @author Wherein <wherein777@163.com>
 * @date 2021-03-15 12:36
 */
class XiaomiPhone implements IphoneProduct
{
    public function start()
    {
        dd('小米-开机');
    }
    public function shutdown()
    {
        dd('小米-关机');
    }
    public function callup()
    {
        dd('小米-打电话');
    }
    public function sendSMS()
    {
        dd('小米-发短信');
    }
}

/**
 * 华为手机
 * @author Wherein <wherein777@163.com>
 * @date 2021-03-15 12:39
 */
class HuaweiPhone implements IphoneProduct
{
    public function start()
    {
        dd('华为-开机');
    }
    public function shutdown()
    {
        dd('华为-关机');
    }
    public function callup()
    {
        dd('华为-打电话');
    }
    public function sendSMS()
    {
        dd('华为-发短信');
    }
}

/**
 * 小米路由器
 * @author Wherein <wherein777@163.com>
 * @date 2021-03-15 12:41
 */
class XiaomiRouter implements IRouteProduct
{
    public function start()
    {
        dd('小米路由器-开启');
    }
    public function shutdown()
    {
        dd('小米路由器-关闭');
    }
    public function openWifi()
    {
        dd('小米路由器-开启wifi');
    }
    public function setting()
    {
        dd('小米路由器-设置');
    }
}

/**
 * 华为路由器
 * @author Wherein <wherein777@163.com>
 * @date 2021-03-15 12:41
 */
class HuaweiRouter implements IRouteProduct
{
    public function start()
    {
        dd('华为路由器-开启');
    }
    public function shutdown()
    {
        dd('华为路由器-关闭');
    }
    public function openWifi()
    {
        dd('华为路由器-开启wifi');
    }
    public function setting()
    {
        dd('华为路由器-设置');
    }
}

/**
 * 抽象产品工厂:超级工厂
 * @author Wherein <wherein777@163.com>
 * @date 2021-03-15 12:44
 */
interface IProductFactory{
    // 生产手机
    public function iphoneProduct();

    // 生产路由器
    public function routeProduct();
}

/**
 * 小米工厂
 * @date 2021-03-15 12:50
 */
class XiaomiFactory implements IProductFactory{
    public function iphoneProduct(){
        return new XiaomiPhone();
    }

    public function routeProduct(){
        return new XiaomiRouter();
    }
}

/**
 * 华为工厂
 * @date 2021-03-15 12:50
 */
class HuaweiFactory implements IProductFactory{
    public function iphoneProduct(){
        return new HuaweiPhone();
    }

    public function routeProduct(){
        return new HuaweiRouter();
    }
}

// 客户端
class Client{
    public static function main(){
        $xiaomiFactory = new XiaomiFactory();
        $xiaomiProduct = $xiaomiFactory->iphoneProduct();
        $xiaomiProduct->callup();
        $xiaomiProduct->sendSMS();
    }
}

// 测试
$client = new Client();
$client::main();